/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package issr.boundary;

import com.vaadin.data.Item;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import issr.boundary.vaadin.AbstractView;
import issr.controller.ControlloreGestionePuntoVendita;
import issr.entity.Puntovendita;
import issr.misc.Labels;
import java.util.ArrayList;

/**
 *
 * @author cecco
 */
public class PannelloGestionePuntoVendita extends AbstractView {

    private ControlloreGestionePuntoVendita controllore;
    private final Table textTable;
    private final VerticalLayout layout;

    public PannelloGestionePuntoVendita() {
        controllore = new ControlloreGestionePuntoVendita();

        layout = new VerticalLayout();
        textTable = new Table();
        textTable.addContainerProperty(Labels.NOME, String.class, null);
        textTable.addContainerProperty(Labels.LOCAZIONE, String.class, null);

        setSizeFull();
        setCompositionRoot(layout);

        layout.setHeight("100%");
        layout.setWidth("100%");
        layout.setSpacing(true);
        layout.setMargin(true);
        layout.addComponent(textTable);
    }

    private void visualizzaPuntiVendita() {
        ArrayList<Puntovendita> puntiVendita = controllore.ottieniPuntiVendita();
        for (int dummyId = 0; dummyId < puntiVendita.size(); dummyId++) {
            Item item = textTable.addItem(dummyId);
            item.getItemProperty(Labels.NOME).setValue(puntiVendita.get(dummyId).getNome());
            item.getItemProperty(Labels.LOCAZIONE).setValue(puntiVendita.get(dummyId).getLocazione());
        }
        textTable.setSizeFull();
        textTable.setPageLength(0);
        textTable.setImmediate(true);
    }

    @Override
    protected void open() throws Exception {
        textTable.removeAllItems();
        visualizzaPuntiVendita();
    }

    @Override
    protected void close() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
